import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controller/test_timer_controller.dart';
import '../controller/counter_controller.dart';
import '../model/controller/timer_controller_item.dart';
import '../widget/timer_widget.dart';
import '../widget/remaining_timer_widget.dart';

class AddPage extends StatelessWidget {
  final TestTimerController _testTimerController =
      Get.put(TestTimerController(60, () {
    debugPrint("${DateTime.now()}==>TestTimerController");
  }));
  //final counterController = Get.find<CounterController>();
  final counterController = Get.put(CounterController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Counter"),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          const Icon(Icons.add),
          const SizedBox(
            height: 7,
          ),
          Obx(
            () => Text(
              _testTimerController.time.value,
              style: const TextStyle(
                fontSize: 18,
                color: Colors.red,
              ),
            ),
          ),
          const SizedBox(
            height: 7,
          ),
          GetX<TestTimerController>(
            //init: _timerController,
            builder: (controler) {
              return Text(
                controler.time.value,
                style: const TextStyle(
                  fontSize: 18,
                  color: Colors.red,
                ),
              );
            },
          ),
          const SizedBox(
            height: 7,
          ),
          GetBuilder<TestTimerController>(
            //init: _timerController,
            builder: (logic) {
              return Text(
                logic.time.value,
                style: const TextStyle(
                  fontSize: 18,
                  color: Colors.red,
                ),
              );
            },
          ),
          const SizedBox(
            height: 7,
          ),
          GetBuilder<CounterController>(builder: (logic) {
            return Text(
              "count:${logic.count}",
              style: const TextStyle(fontSize: 50),
            );
          }),
          const SizedBox(
            height: 7,
          ),
          ElevatedButton(
            onPressed: counterController.increase,
            child: const Icon(Icons.add),
          ),
          const SizedBox(
            height: 7,
          ),
          TimerWidget(
              tag: "one",
              seconds: 120,
              callback: () {
                debugPrint("${DateTime.now()}==>${this}");
              },
            color: Colors.red,
          ),
          TimerWidget(
              tag: "two",
              seconds: 90,
              callback: () {
                debugPrint("${DateTime.now()}==>${this}");
              },
            color: Colors.green,
          ),
          TimerWidget(
              tag: "three",
              seconds: 60,
              callback: () {
                debugPrint("${DateTime.now()}==>${this}");
              },
            color: Colors.blue,
          ),
          RemainingTimerWidget(
            tag: "one",
            remainingSeconds: 10,
            timeoutSeconds: 60,
            color: Colors.lightGreen,
            callback: () {
              Future.delayed(const Duration(seconds: 3), () {
                debugPrint("${DateTime.now()}==>one minuts Future.delayed");
              });
              debugPrint(
                  "${DateTime.now()}==>one minuts  RemainingTimerWidget");
            },
          ),
          RemainingTimerWidget(
            tag: "two",
            remainingSeconds: 30,
            timeoutSeconds: 120,
            color: Colors.lightGreen,
            callback: () {
              Future.delayed(const Duration(seconds: 3), () {
                debugPrint("${DateTime.now()}==>two minuts Future.delayed");
              });
              debugPrint(
                  "${DateTime.now()}==>two minuts  RemainingTimerWidget");
            },
          )
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: counterController.increase,
        child: const Icon(Icons.add),
      ),
    );
  }
}
